package com.heima.behavior.controller;


import com.heima.behavior.entity.ApUnlikesBehavior;
import com.heima.behavior.service.IApUnlikesBehaviorService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.behavior.dto.BehaviorDto;
import com.heima.common.Threadlocals.UserThreadLocalUtil;
import com.heima.common.dto.ResponseResult;
import com.heima.common.dto.User;
import com.heima.common.enums.AppHttpCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.behavior.service.IApUnlikesBehaviorService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * APP不喜欢行为表 前端控制器
 * </p>
 *
<<<<<<< HEAD
 * @author itheima
=======
 * @author chen
>>>>>>> a03872222b7ff141224d6c769df39a8acb897588
 * @since 2022-08-04
 */
@RestController
@RequestMapping("/api/v1/unlikes_behavior")
@Api(tags = "APP不喜欢行为表接口")
@CrossOrigin
public class ApUnlikesBehaviorController{

    @Autowired
    private IApUnlikesBehaviorService apUnlikesBehaviorService;


    /**
     * 根据文章ID和设备ID查询是否喜欢
     * @param articleId
     * @param entryId
     * @return
     */
    @GetMapping
    public ApUnlikesBehavior findApUnlikesBehavior(@RequestParam("articleId") Integer articleId, @RequestParam("entryId") Integer entryId){
        return apUnlikesBehaviorService.findByArticleIdAndEntryId(articleId,entryId);
    }



    @PostMapping
    public ResponseResult unlike(@RequestBody BehaviorDto dto){
        User user = UserThreadLocalUtil.get();
        if(user == null){
            return ResponseResult.errorResult(AppHttpCodeEnum.NEED_LOGIN);
        }
        return apUnlikesBehaviorService.unlike(dto);
    }


}
